if exists (select 1
            from  sysobjects
           where  id = object_id('bd_visitor_record')
            and   type = 'U')
   drop table bd_visitor_record
go

/*==============================================================*/
/* Table: bd_visitor_record                                     */
/*==============================================================*/
create table bd_visitor_record (
   id                   bigint               not null,
   visitor_name         varchar(64)          null,
   visitor_tel          varchar(20)          null,
   visit_place          varchar(100)         null,
   employee_name        varchar(64)          null,
   sj                   datetime             not null default getdate(),
   is_do                int                  not null default 1,
   remark               varchar(200)         null,
   constraint PK_BD_VISITOR_RECORD primary key (id, sj)
)
go

if exists (select 1 from  sys.extended_properties
           where major_id = object_id('bd_visitor_record') and minor_id = 0)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '访客——访客授权记录
   有效时间段为当日',
   'user', @CurrentUser, 'table', 'bd_visitor_record'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'id')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'id'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   'id',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'id'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'visitor_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'visitor_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '访客姓名',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'visitor_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'visitor_tel')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'visitor_tel'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '访客手机号',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'visitor_tel'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'visit_place')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'visit_place'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '访问地点',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'visit_place'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'employee_name')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'employee_name'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '被访人姓名',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'employee_name'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'sj')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'sj'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '授权时间',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'sj'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'is_do')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'is_do'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '是否授权：0授权失败，1授权成功',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'is_do'
go

if exists(select 1 from sys.extended_properties p where
      p.major_id = object_id('bd_visitor_record')
  and p.minor_id = (select c.column_id from sys.columns c where c.object_id = p.major_id and c.name = 'remark')
)
begin
   declare @CurrentUser sysname
select @CurrentUser = user_name()
execute sp_dropextendedproperty 'MS_Description',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'remark'

end


select @CurrentUser = user_name()
execute sp_addextendedproperty 'MS_Description',
   '备注',
   'user', @CurrentUser, 'table', 'bd_visitor_record', 'column', 'remark'
go
